package com.battery.controller;

import com.battery.pojo.Rule;
import com.battery.service.RuleService;
import com.battery.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "计费规则管理相关接口")
@RequestMapping("/rule")
public class RuleController {
   @Autowired
    private RuleService ruleService;
    @PostMapping("/addRule")
    @ResponseBody
    @ApiOperation("添加计费规则")
    //public Result addMerchant(@RequestBody @ApiParam(name="商铺对象",value="传入json格式",required=true) MerChant merChant) {
    //    return merChantService.insert(merChant);
    //}
    public Result addRule(@RequestBody @ApiParam(name="计费规则对象",value="传入json格式",required=true) Rule rule){
        Result result = ruleService.addRule(rule);
        return Result.ok().data("data",result);
    }
    @DeleteMapping("/deleteRule/{rule_id}")
    @ResponseBody
    @ApiOperation("删除计费规则")
    public Result deleteRule(@RequestBody @ApiParam(name="计费规则id",required=true) int rule_id){
        Result result = ruleService.deleteRule(rule_id);
        return Result.ok().data("data",result);
    }
    @PutMapping("/updateRule")
    @ResponseBody
    @ApiOperation("更新计费规则")
    public Result updateRule(@RequestBody @ApiParam(name="计费规则id",required=true) Rule rule){
        Result result = ruleService.updateRule(rule);
        return Result.ok().data("data",result);
    }
    @PostMapping("/findRule/{rule_id}")
    @ResponseBody
    @ApiOperation("查询计费规则")
    public Result findRule(@RequestBody @ApiParam(name="计费规则id",required=true) int rule_id){
        Result result = ruleService.findRule(rule_id);
        return Result.ok().data("data",result);
    }
}
